package com.feng.ioc.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class Windowscondition implements Condition {
    //conditionContext 判断条件能使用的上下文
    //annotatedTypeMetadata  当前Bean的注释信息
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //获得ioc使用的beanFactory
        ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();
        //获得类加载器
        ClassLoader classLoader = conditionContext.getClassLoader();
        //获得当前环境信息
        Environment environment = conditionContext.getEnvironment();
        //获得bean的注册类
        BeanDefinitionRegistry registry = conditionContext.getRegistry();

        if (environment.getProperty("os.name").contains("Windows")){
            return true;
        }
        return false;
    }
}
